/**
 * 1837. K 进制表示下的各位数字总和
 * https://leetcode-cn.com/problems/sum-of-digits-in-base-k/
 */
public class Solutions_1837 {
    public static void main(String[] args) {
//        int n = 34, k = 6;  // output: 9
        int n = 10, k = 10;  // output: 1

        int result = sumBase(n, k);
        System.out.println(result);
    }

    /**
     * 除 k 取余法
     */
    public static int sumBase(int n, int k) {
        if (n == k) {
            return 1;
        }
        int res = 0;
        while (n > 0) {
            res += n % k;
            n = n / k;
        }
        return res;
    }
}
